use std::mem::MaybeUninit;
use sqlx::{MySqlConnection, MySqlPool};
use crate::{config::MY_SQL_URL, error::AppErr};


pub type Pool = MySqlPool;
pub type Conn = MySqlConnection;

static mut POOL: MaybeUninit<Pool> = MaybeUninit::uninit();

pub mod device;
pub mod cargo;
pub mod product;
pub mod order;
pub mod firm;
pub mod adv;
pub mod adv_cfg;

pub async fn init() -> Result<(), AppErr> {
    let pool = Pool::connect(MY_SQL_URL).await?;
    unsafe { POOL.write(pool); }
    Ok(())
}

#[inline(always)]
pub fn get_pool() -> &'static Pool {
    unsafe { POOL.assume_init_ref() }
}

